using System.Configuration;

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;

using EnterpriseLibraryContrib.Data.SQLite;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EnterpriseLibraryContrib.Data.SQLite.Tests
{
    [TestClass]
    public class SQLiteDatabaseAssemblerFixture
    {
        private ConfigurationReflectionCache reflectionCache;
        private IConfigurationSource configurationSource;

        [TestInitialize]
        public void SetUp()
        {
            reflectionCache = new ConfigurationReflectionCache();
            configurationSource = new SystemConfigurationSource();
        }

        [TestMethod]
        public void CanGetAssemblerForSQLiteDatabase()
        {
            IDatabaseAssembler assembler
                = new DatabaseCustomFactory().GetAssembler(typeof(SQLiteDatabase), "ignore", reflectionCache);

            Assert.IsNotNull(assembler);
        }

        [TestMethod]
        public void AssemblerCanAssembleSQLiteDatabase()
        {
            ConnectionStringSettings settings
                = new ConnectionStringSettings("name", "test;", "System.Data.SQLite");

            IDatabaseAssembler assembler
                = new DatabaseCustomFactory().GetAssembler(typeof(SQLiteDatabase), settings.Name, reflectionCache);
            Database database = assembler.Assemble(settings.Name, settings, configurationSource);

            Assert.IsNotNull(database);
            Assert.AreSame(typeof(SQLiteDatabase), database.GetType());
            Assert.AreEqual(settings.ConnectionString, database.ConnectionStringWithoutCredentials);
        }
    }
}
